(function(){
	var AjaxCrud = QualityCheck.AjaxCRUD;
	var serverUrl = QualityCheck.GPUD.ServiceConfig;
	var currentPage = 1;
	var pageSize = 10;
	var totalSize;
	var now = 0;
	var dataCache = [];
	$(function(){
		var usercode = $("#user-name",parent.parent.document).attr("code");
		var userkey = $("#user-name",parent.parent.document).attr("key");
		var usertype = $("#user-name",parent.parent.document).attr("usertype");
		keyCheck(usercode,usertype,userkey,function(){
			initSmPages();
			window.onresize = function () {
				initSmPages();
			};
			pagebtns();
			teacherSeachMenu();
			initTeacher(currentPage,pageSize);
		});
	});
	function initTeacher(currentpage,pagesize){
		var userKey = $("#user-name",parent.parent.document).attr("key");	
		var schoolcode = $("#user-name",parent.parent.document).attr("schoolcode");
		var rolecode = $("#user-name",parent.parent.document).attr("rolecodes");
		var usertype = $("#user-name",parent.parent.document).attr("usertype");
		var islock = $("#teacher-lock option:selected").val();
		var department1 = $("#teacher-grade option:selected").text();
		var department2 = $("#teacher-class option:selected").text();
		var name = $("#teacher-name").val();
		debugger;
		var data = {
				cmd:"getAllTeachers",
				model:"teacher",
				userKey:userKey,
				data:{
					currentpage:currentpage,
					pagesize:pagesize,
					department1:encodeURI(department1),
					department2:encodeURI(department2),
					name:encodeURI(name),
					del:islock,
					schoolcode:schoolcode,
					rolecode:rolecode,
					usertype:usertype
				},
				remark:"",
				
		};
		AjaxCrud.get(serverUrl.ServerLoginUrl,data,function(res){
			var content = "";
			var pagecontent = "<div class=\"pages-btn-next\">&gt;&gt;</div>";
			if(res.result == 1 && res.data != undefined && res.data != ""){
				var data = res.data.data;
				var total = res.data.total;
				totalSize = Math.ceil(total/pagesize);
				if(totalSize <= 5 && totalSize >0){
					for(var i = totalSize-1 ; i >= 0; i--){
						if(i == currentpage-1){
							pagecontent += "<div class=\"pages-btn page-btn-select\">"+(i + 1)+"</div>"; 
						}else{
							pagecontent += "<div class=\"pages-btn\">"+(i + 1)+"</div>"; 
						}
					}
				}else if(totalSize == 0){
					pagecontent += "<div class=\"pages-btn\">1</div>";
				}else if(totalSize > 5){
					var lastp = (now*5)+5;
					if(lastp > totalSize){
						lastp = totalSize;
					}
					for(var i = lastp-1 ; i >= (now*5); i--){
						if(i == currentpage-1){
							pagecontent += "<div class=\"pages-btn page-btn-select\">"+(i + 1)+"</div>"; 
						}else{
							pagecontent += "<div class=\"pages-btn\">"+(i + 1)+"</div>"; 
						}
					}
				}
				pagecontent += "<div class=\"pages-btn-last\">&lt;&lt;</div>";
				$("#student-page").empty();
				$("#student-page").append(pagecontent);
				
				$(".pages-btn").unbind("click");
				$(".pages-btn").click(function(){
					$(".pages-btn").removeClass("page-btn-select");
					$(this).addClass("page-btn-select");
					currentPage = parseInt($(this).text());
					initTeacher(currentPage,pageSize);
				});
				
				$(".pages-btn-last").unbind("click");
				$(".pages-btn-last").click(function(){
					if(totalSize <= 5 && totalSize >0){
						return false;
					}else if(totalSize == 0){
						return false;
					}else if(totalSize > 5){
						if(now > 0){
							now --;
							initTeacher((now*5+1),pageSize);
						}else{
							return false;
						}
					}
				});
				
				$(".pages-btn-next").unbind("click");
				$(".pages-btn-next").click(function(){
					if(totalSize <= 5 && totalSize >0){
						return false;
					}else if(totalSize == 0){
						return false;
					}else if(totalSize > 5){
						if(totalSize%5 == 0){
							if((now+1) < totalSize/5){
								now ++;
								initTeacher((now*5+1),pageSize);
							}else{
								return false;
							}
						}else{
							if(totalSize > (now+1)*5){
								now ++;
								initTeacher((now*5+1),pageSize);
							}else{
								return false;
							}
						}
					}
				});
				
				if(data.length > 0){
					dataCache = [];
					for(var i = 0; i < data.length; i++){
						for(var key in data[i]){
							if(data[i][key] == null || data[i][key] == "null" || data[i][key] == undefined){
								data[i][key] = "";
							}
						}
						var lockBtns = "";
						if(islock == 1){
							lockBtns = "<div class=\"table-edit\" dataindex = \""+i+"\" teachercode=\""+data[i].teachercode+"\" title=\"编辑\"></div>" +
									   "<div class=\"table-locked\" teachercode=\""+data[i].teachercode+"\" title=\"锁定\"></div>";
						}else if(islock == 0){
							lockBtns = "<div class=\"table-unlocked\" teachercode=\""+data[i].teachercode+"\" title=\"解锁\"></div>"+
								       "<div class=\"table-delete\" dataindex = \""+i+"\" teachercode=\""+data[i].teachercode+"\" cellphone=\""+data[i].cellphone+"\" title=\"删除\"></div>";
						}
						content += "<div class=\"table-trs\">" +
//							"<div class=\"tables-headimg\">" +
//								"<img src=\"../../../../../../smartSchoolService"+data[i].headimg+"\" width=\"100%\" height=\"100%\"/>" +
//							"</div>" +
							"<div class=\"tables-left\">" +
								"<div class=\"table-name\" title=\""+data[i].name+"\"\>"+substr(data[i].name,8)+"</div>" +
								"<div class=\"table-code\">"+data[i].teachercode+"</div>" +
							"</div>" +
							"<div class=\"tables-middle\">" +
								"<div class=\"table-class\" title='"+data[i].work+"' style='width:150px;'>"+substr(data[i].work,6)+"</div>" +
								"<div class=\"table-code\" style='width:150px;'>"+data[i].cellphone+"</div>" +
							"</div>" +
							"<div class=\"tables-right\">" +
								"<div class=\"table-address\" title=\""+data[i].birpacle+"\">"+substr(data[i].birpacle,12)+"</div>" +
								"<div class=\"table-oprate\">" +
									"<div class=\"table-detail\" dataindex = \""+i+"\" teachercode=\""+data[i].teachercode+"\" title=\"详情\"></div>" +
									lockBtns +
								"</div>" +
							"</div>" +
						"</div>";
						dataCache.push(data[i]);
					}
					$("#teacher-data-show").empty();
					$("#teacher-data-show").append(content);
					
					$(".table-trs").unbind("hover");
					$(".table-trs").hover(function(){
						$(this).find(".table-oprate").show();
					},function(){
						$(".table-oprate").hide();
					});
					
					$(".table-detail").unbind("click");
					$(".table-detail").click(function(){
						var index = parseInt($(this).attr("dataindex"));
						$("#teacher-form-show").show();
						$("#right-tables").hide();
						$("#teacher-form-show").contents().find("input").attr("disabled","disabled");
						$("#teacher-form-show").contents().find("input").css("background-color","#E5E5E5");
						$("#teacher-form-show").contents().find("select").attr("disabled","disabled");
						$("#teacher-form-show").contents().find("select").css("background-color","#E5E5E5");
						$("#teacher-form-show").contents().find("#back-to-table").unbind("click");
						$("#teacher-form-show").contents().find("#back-to-table").click(function(){
							$("#teacher-form-show").hide();
							$("#right-tables").show();
						});
						showData(dataCache[index],"detail");
					});
					
					$(".table-edit").unbind("click");
					$(".table-edit").click(function(){
						var index = parseInt($(this).attr("dataindex"));
						$("#teacher-form-show").show();
						$("#right-tables").hide();
						$("#teacher-form-show").contents().find("input").removeAttr("disabled");
						$("#teacher-form-show").contents().find("input").css("background-color","#fff");
						$("#teacher-form-show").contents().find("select").removeAttr("disabled");
						$("#teacher-form-show").contents().find("select").css("background-color","#fff");
						$("#teacher-form-show").contents().find("#back-to-table").unbind("click");
						$("#teacher-form-show").contents().find("#back-to-table").click(function(){
							$("#teacher-form-show").hide();
							$("#right-tables").show();
						});
						showData(dataCache[index],"edit");
						
						check1("teacher-cellphone",checkMobilePhone,"checkAddNull","teacher-form-show");
						check1("teacher-name",isNull,"null","teacher-form-show");
						check1("teacher-cardid",checkCard,"check","teacher-form-show");
						check1("teacher-teachercode",checkNum,"checkAddNull","teacher-form-show");
						check1("teacher-birdate",isNull,"null","teacher-form-show");
						check1("teacher-inschooldate",isNull,"null","teacher-form-show");
						check1("teacher-workdate",isNull,"null","teacher-form-show");
						checkTwoDate1("teacher-inschooldate","teacher-workdate","teacher-form-show");
						
						$("#teacher-form-show").contents().find("#save-btns").unbind("click");
						$("#teacher-form-show").contents().find("#save-btns").click(function(){
							if(checkSave()){
								if(check2()){
									updateTeacher();
								}
							}
						});
					});
					
					$(".table-locked").unbind("click");
					$(".table-locked").click(function(){
						var studentcode = $(this).attr("teachercode");
						var usercode = $(this).attr("cellphone");
						deleteBox("确定要锁定吗？",function(){
							lockTeacher(studentcode,usercode);
						});	
					});
					
					$(".table-unlocked").unbind("click");
					$(".table-unlocked").click(function(){
						var studentcode = $(this).attr("teachercode");
						deleteBox("确定要解锁吗？",function(){
							unlockTeacher(studentcode);
						});
						
					});
					$(".table-delete").unbind("click");
					$(".table-delete").click(function(){
						var teachercode = $(this).attr("teachercode");
						var cellphone = $(this).attr("cellphone");
						deleteBox("确定要删除吗？",function(){
							deleteTeacher(teachercode,cellphone);
						});
					});
					
				}else{
					content += "<div class=\"table-trs\">" +
									"<div class=\"no-data-show\">没有查到相关结果！</div>" +
								"</div>";
					$("#teacher-data-show").empty();
					$("#teacher-data-show").append(content);
				}
			}else{
				content += "<div class=\"table-trs\">" +
								"<div class=\"no-data-show\">没有查到相关结果！</div>" +
							"</div>";
				$("#teacher-data-show").empty();
				$("#teacher-data-show").append(content);
			}
			initRegon();
		},null,null);	
	}
	function initRegon(){
		var userKey = $("#user-name",parent.parent.document).attr("key");
		var schoolcode = $("#user-name",parent.parent.document).attr("schoolcode");
		var data = {
				cmd:"getAllDepartments",
				model:"department",
				userKey:userKey,
				data:{
					schoolcode:schoolcode
				},
				remark:"",						
		};
		AjaxCrud.get(serverUrl.ServerLoginUrl,data,function(res){
			if(res.result == 1 && res.data != undefined && res.data != ""){
				var data = res.data;
				departments = data;
				var contents = "<option departmentcodes = '' value='科室'>部门</option>";
				for(var i = 0; i < data.length; i++){
					contents += "<option departmentcodes='"+data[i].departmentcode+"' value='"+data[i].office+"'>"+data[i].department+"</option>";
				}
				var dept1 = $("#teacher-form-show").contents().find("#teacher-department1 option:selected").val();
				$("#teacher-form-show").contents().find("#teacher-department1").empty();
				$("#teacher-form-show").contents().find("#teacher-department1").append(contents);
				$("#teacher-form-show").contents().find("#teacher-department1").val(dept1);
				$("#teacher-form-show").contents().find("#teacher-department1").unbind("change");
				$("#teacher-form-show").contents().find("#teacher-department1").change(function(){
					var classes = $("#teacher-form-show").contents().find("#teacher-department1 option:selected").val();
					var classcodes = $("#teacher-form-show").contents().find("#teacher-department1 option:selected").attr("departmentcodes");
					$("#teacher-form-show").contents().find("#teacher-department2").empty();
					var classArr = classes.split(",");
					var classcodeArr = classcodes.split(",");
					var cont = "";
					for(var i = 0; i < classArr.length; i++){
						cont += "<option value='"+classcodeArr[i]+"'>"+classArr[i]+"</option>";
					}
					$("#teacher-form-show").contents().find("#teacher-department2").append(cont);						
				});
				
			}else{
				
			}
		},null,null);
	}
	function lockTeacher(teachercode){
		var userKey = $("#user-name",parent.parent.document).attr("key");	
		var data = {
				cmd:"batchDeleteTeachersByCodes",
				model:"teacher",
				userKey:userKey,
				data:{
					teachercodes:[teachercode],
				},
				remark:"",						
		};
		processBegin("正在锁定中···");
		AjaxCrud.get(serverUrl.ServerLoginUrl,data,function(res){
			if(res.result == 1 && res.data != undefined && res.data != ""){
				processEnd("锁定成功");
				initTeacher(currentPage,pageSize);
			}else{
				processError("锁定失败");
			}
		},null,null);
	}
	function unlockTeacher(teachercode){
		var userKey = $("#user-name",parent.parent.document).attr("key");
		var param = {};
		param["del"] = "1";
		param["teachercode"] = teachercode;
		
		var data = {
				cmd:"unLockTeachersByCodes",
				model:"teacher",
				userKey:userKey,
				data:param,
				remark:"",						
		};
		processBegin("正在解锁中···");
		AjaxCrud.get(serverUrl.ServerLoginUrl,data,function(res){
			if(res.result == 1 && res.data != undefined && res.data != ""){
				processEnd("解锁成功");
				closeDialog(function(){initTeacher(currentPage,pageSize);});					
			}else{
				processError("解锁失败");
			}
		},null,null);
	}
	function deleteTeacher(teachercode,usercode){
		var userKey = $("#user-name",parent.parent.document).attr("key");
		var param = {};
		param["teachercode"] = teachercode;
		param["cellphone"] = usercode;
		var data = {
				cmd:"delete",
				model:"teacher",
				userKey:userKey,
				data:param,
				remark:"",						
		};
		processBegin("正在删除中···");
		AjaxCrud.get(serverUrl.ServerLoginUrl,data,function(res){
			if(res.result == 1 && res.data != undefined && res.data != ""){
				processEnd("删除成功");
				closeDialog(function(){initTeacher(1,pageSize);});					
			}else{
				processError("删除失败");
			}
		},null,null);
	}
	function substr(str,len){
		if(str != undefined){
			if(str.length > len){
				str = str.substring(0,len-2)+"...";
				return str;
			}else{
				return str;
			}
		}else{
			return "";
		}
	}
	function showData(data,type){
		if(type == "detail"){
			$("#teacher-form-show").contents().find("#save-btns-content").hide();
		}else if(type == "edit"){
			$("#teacher-form-show").contents().find("#save-btns-content").show();
		}
		for(var key in data){
			if($("#teacher-form-show").contents().find("#teacher-" + key)[0]){
				if($("#teacher-form-show").contents().find("#teacher-" + key)[0].tagName.toLocaleLowerCase() == "input"){
					if(key=="birdate"){
						$("#teacher-form-show").contents().find("#teacher-" + key).val(getSmpFormatDateByLong(data[key], "a"));
					}else if(key=="inschooldate"){
						$("#teacher-form-show").contents().find("#teacher-" + key).val(getSmpFormatDateByLong(data[key], "a"));
					}else if(key=="workdate"){
						$("#teacher-form-show").contents().find("#teacher-" + key).val(getSmpFormatDateByLong(data[key], "a"));
					}else{
						$("#teacher-form-show").contents().find("#teacher-" + key).val(data[key]);
					}
					$("#teacher-form-show").contents().find("#teacher-department1 option:selected").val();
				}else if($("#teacher-form-show").contents().find("#teacher-" + key)[0].tagName.toLocaleLowerCase() == "select"){
					if(key=="department1"){
//						var department1 = $("#teacher-form-show").contents().find("#teacher-department1 option");
//						for(var i = 0; i< department1.length; i++){
							var dept1 = data[key];
							$("#teacher-form-show").contents().find("#teacher-department1").val(dept1);
//							if(department1[i].getAttribute("value").indexOf(classcode) != -1){
//								department1[i].setAttribute("selected",true);
//								$("#teacher-form-show").contents().find("#teacher-department1").change();
//							}
							debugger;
								var classes = $("#teacher-form-show").contents().find("#teacher-department1 option:selected").val();
								var classcodes = $("#teacher-form-show").contents().find("#teacher-department1 option:selected").attr("departmentcodes");
								$("#teacher-form-show").contents().find("#teacher-department2").empty();
								var classArr = classes.split(",");
								var classcodeArr = classcodes.split(",");
								var cont = "";
								for(var i = 0; i < classArr.length; i++){
									cont += "<option value='"+classcodeArr[i]+"'>"+classArr[i]+"</option>";
								}
								$("#teacher-form-show").contents().find("#teacher-department2").append(cont);						
//						}
					}else if(key=="department2"){
						var dept2 = data[key];
						
						$("#teacher-form-show").contents().find("#teacher-department2 option").each(function(){
						   if($(this).text() === dept2){
						      $(this).attr('selected', 'selected');
						   }
						});
					}else{
						var len = $("#teacher-form-show").contents().find("#teacher-" + key+" option");
						for(var i = 0; i < len.length ; i++){
							if(len[i].value == data[key]){
								len[i].selected = true;
							}
						}
					}
				}
			}
		}
	}
	
	function updateTeacher(){
		var tteacher = getFormData();
		var userKey = $("#user-name",parent.parent.document).attr("key");
		var obj = {};
		for(var key in tteacher){
			if(tteacher[key] != "" && tteacher[key] != undefined){
				obj[key] = tteacher[key];
			}
		}
		
		var data = {
				cmd:"updateTeacher",
				model:"teacher",
				userKey:userKey,
				data:obj,
				remark:"",						
		};
		processBegin("正在保存中···");
		AjaxCrud.get(serverUrl.ServerLoginUrl,data,function(res){
			if(res.result == 1 && res.data != undefined && res.data != ""){
				processEnd("编辑教师信息成功");
				initTeacher(currentPage,pageSize);	
			}else{
				processError("编辑教师信息失败");
			}
		},null,null);
	}
	
	function getFormData(){
		new setTTeacher(null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null);
		var tteacher = getTTeacher();
		var obj = {};
		for(var key in tteacher){
			if($("#teacher-form-show").contents().find("#teacher-"+key)[0]){
				if($("#teacher-form-show").contents().find("#teacher-"+key)[0].tagName.toLocaleLowerCase() == "input"){
					if(key=="birdate"){
						obj[key] = strToDate($("#teacher-form-show").contents().find("#teacher-"+key).val());
					}else if(key=="inschooldate"){
						obj[key] = strToDate($("#teacher-form-show").contents().find("#teacher-"+key).val());
					}else if(key=="workdate"){
						obj[key] = strToDate($("#teacher-form-show").contents().find("#teacher-"+key).val());
					}else{
						obj[key] = encodeURI($("#teacher-form-show").contents().find("#teacher-"+key).val());
					};
				}else{
					if(key=="department2"){
						obj[key] = encodeURI($("#teacher-form-show").contents().find("#teacher-"+key+" option:selected").text());
						obj["departmentcode"] = encodeURI($("#teacher-form-show").contents().find("#teacher-"+key+" option:selected").val());
					}else{
						obj[key] = encodeURI($("#teacher-form-show").contents().find("#teacher-"+key+" option:selected").val());
					}
				}
			}
		}
		var schoolcode = $("#user-name",parent.parent.document).attr("schoolcode");
		obj.schoolcode = schoolcode;
		new setTTeacher(obj.schoolcode,obj.name,obj.birdate,obj.sex,obj.cellphone,obj.cardid,obj.birpacle,obj.nation,obj.political,obj.phone,obj.remark,obj.teachercode,obj.work,obj.department1,obj.department2,obj.departmentcode,obj.inschooldate,obj.workdate,obj.degree,obj.graduation,obj.tjob,obj.issueorg);
		return getTTeacher();	
	}
	
	function check2(){
		var flg = false;
		var checkFails = $("#teacher-form-show").contents().find(".check-fail");
		for(var i = 0; i < checkFails.length; i++){
			if(checkFails[i].innerHTML != ""){
				flg = false;
				break;
			}else{
				flg = true;
			}
		}
		return flg;
	}
	
	function checkSave(){
		if($("#teacher-form-show").contents().find("#teacher-name").val() == ""){
			$("#teacher-form-show").contents().find("#teacher-name").focus();
			$("#teacher-form-show").contents().find("#teacher-name-ex").text("不能为空！");
			return false;
		}else if($("#teacher-form-show").contents().find("#teacher-birdate").val() == ""){
			$("#teacher-form-show").contents().find("#teacher-birdate").focus();
			$("#teacher-form-show").contents().find("#teacher-birdate-ex").text("不能为空！");
			return false;
		}else if($("#teacher-form-show").contents().find("#teacher-cellphone").val() == ""){
			$("#teacher-form-show").contents().find("#teacher-cellphone").focus();
			$("#teacher-form-show").contents().find("#teacher-cellphone-ex").text("不能为空！");
			return false;
		}else if($("#teacher-form-show").contents().find("#teacher-teachercode").val() == ""){
			$("#teacher-form-show").contents().find("#teacher-teachercode").focus();
			$("#teacher-form-show").contents().find("#teacher-teachercode-ex").text("不能为空！");
			return false;
		}else if($("#teacher-form-show").contents().find("#teacher-department1").val() == "科室"){
			$("#teacher-form-show").contents().find("#teacher-department1").focus();
			return false;
		}else if($("#teacher-form-show").contents().find("#teacher-inschooldate").val() == ""){
			$("#teacher-form-show").contents().find("#teacher-inschooldate").focus();
			$("#teacher-form-show").contents().find("#teacher-inschooldate-ex").text("不能为空！");
			return false;
		}else if($("#teacher-form-show").contents().find("#teacher-workdate").val() == ""){
			$("#teacher-form-show").contents().find("#teacher-workdate").focus();
			$("#teacher-form-show").contents().find("#teacher-workdate-ex").text("不能为空！");
			return false;
		}else{
			return true;
		}
	}
	
	//部门科室二级联动菜单
	function teacherSeachMenu(){
		var userKey = $("#user-name",parent.parent.document).attr("key");
		var schoolcode = $("#user-name",parent.parent.document).attr("schoolcode");
		var data = {
				cmd:"getAllDepartments",
				model:"department",
				userKey:userKey,
				data:{
					schoolcode:schoolcode
				},
				remark:"",						
		};
		AjaxCrud.get(serverUrl.ServerLoginUrl,data,function(res){
			if(res.result == 1 && res.data != undefined && res.data != ""){
				var data = res.data;
				departments = data;
				var contents = "<option departmentcodes = '' value='科室'>部门</option>";
				for(var i = 0; i < data.length; i++){
					contents += "<option departmentcodes='"+data[i].departmentcode+"' value='"+data[i].office+"'>"+data[i].department+"</option>";
				}
				$("#teacher-grade").empty();
				$("#teacher-grade").append(contents);
				$("#teacher-grade").unbind("change");
				$("#teacher-grade").change(function(){
					var classes = $("#teacher-grade option:selected").val();
					var classcodes = $("#teacher-grade option:selected").attr("departmentcodes");
					$("#teacher-class").empty();
					var classArr = classes.split(",");
					var classcodeArr = classcodes.split(",");
					var cont = "";
					for(var i = 0; i < classArr.length; i++){
						cont += "<option value='"+classcodeArr[i]+"'>"+classArr[i]+"</option>";
					}
					$("#teacher-class").append(cont);						
				});
				
			}else{
				
			}
		},null,null);
	} 
	function leadingInTeachers(){
		processBegin("正在导入中···");
		var schoolid = $("#user-name",parent.parent.document).attr("schoolcode");
		var url = Host + "/service/fileupload.do?clazz=teacher&schoolid="+schoolid;
		var options = {
	            url: url, 
	            type : "POST",
	            success :function(result){
	            	if(result.result == 1){
	            		processEnd("导入成功");
	            	}else{
	            		processError("导入失败");
	            	}
	            },
	    };
	    $("#form",parent.parent.parent.document).ajaxSubmit(options);
	}
	function leadingOutTeachers(){
		var userKey = $("#user-name",parent.parent.document).attr("key");	
		var schoolcode = $("#user-name",parent.parent.document).attr("schoolcode");
		var rolecode = $("#user-name",parent.parent.document).attr("rolecodes");
		var usertype = $("#user-name",parent.parent.document).attr("usertype");
		var islock = $("#teacher-lock option:selected").val();
		var department1 = $("#teacher-grade option:selected").text();
		var department2 = $("#teacher-class option:selected").text();
		var name = $("#teacher-name").val();
//		
//		var userKey = $("#user-name",parent.parent.document).attr("key");
//		var schoolcode = $("#user-name",parent.parent.document).attr("schoolcode");
//		var islock = $("#teacher-lock option:selected").val();
//		var name = $("#teacher-name").val();
		var data = {
			cmd: "getAllTeachers",
			model: "teacher",
			userKey: userKey,
			data:{
//				name: name,
//				del : islock,
				isdownload: "true",
//				schoolcode: schoolcode
				department1:encodeURI(department1),
				department2:encodeURI(department2),
				name:encodeURI(name),
				del:islock,
				schoolcode:schoolcode,
				rolecode:rolecode,
				usertype:usertype
				
			},
			remark:"",						
		};
		processBegin("正在导出中···");
		AjaxCrud.get(serverUrl.ServerLoginUrl,data,function(res){
			if(res.result == 1 && res.data != undefined && res.data != ""){
				if(res.data.remark.flag == true){
					var url = Host + res.data.remark.msg;
					window.frames["hrong"].location = url;
					processEnd("导出成功！");
				}else{
					processError("导出失败！");
				}
			}else{
				processError("暂无数据！");
			}
		},null,null);
	}
	function pagebtns(){
		$("#teacher-name").unbind("keyup");
		$("#teacher-name").keyup(function(){
			this.value=this.value.replace(/^ +| +$/g,'');
		});
		document.onkeydown = function(e){ 
			$("select").blur();
		    var ev = document.all ? window.event : e;
		    if(ev.keyCode==13) {
		    	now = 0;
				initTeacher(1,pageSize);
		    }
		};
		$("#teacher-search-btn").click(function(){
			now = 0;
			initTeacher(1,pageSize);
		});
		$("#downloadModel").click(function(){
			deleteBox("确定要下载吗？",function(){
				window.frames["hrong"].location = Host + "/uploads/excle/models/teachers-model.xls";		
			});
		});
		$("#leadingIn").click(function(){
			leadingDialog(function(){
				var content = "<tr style='height:70px;'>" +
						"<td class='table-left'><font color='red'>*</font>文件：</td>" +
						"<td class='table-middle'><input type='file' name='file' id='upload' style='height:21px;width:140px;'></td>" +
						"</tr>";
				$(".leading-dialog-table",parent.parent.parent.document).html(content);
				$("#cancelBtn",parent.parent.parent.document).unbind("click");
				$("#cancelBtn",parent.parent.parent.document).click(function(){
					$(".index-dialog-cover",parent.parent.parent.document).hide();
					$(".leading-dialog",parent.parent.parent.document).hide();
				});
				$("#sureBtn",parent.parent.parent.document).unbind("click");
				$("#sureBtn",parent.parent.parent.document).click(function(){
					$(".index-dialog-cover",parent.parent.parent.document).hide();
					$(".leading-dialog",parent.parent.parent.document).hide();
					leadingInTeachers();
				});
			});
		});
		$("#leadingOut").click(function(){
			var content = "";
			var name = $("#teacher-name").val();
			var islock = $("#teacher-lock option:selected").val();
			var depart1 = $("#teacher-grade option:selected").text();
			var depart2 = $("#teacher-class option:selected").text();
			if(depart1 == "部门" && depart2 == "科室"){
				content += "全部教师";
			}else if(depart1 != "部门" && depart2 == "科室"){
				content += depart1;
			}else{
				content += depart1 + depart2;
			}
			if(name != ""){
				content += name;
			}
			if(islock == "0" || islock == 0){
				content += "（锁定状态  ）";
			}
			deleteBox("您选择的是   <span class='span-class'>"+content+"</span>  ，</br>确定要导出吗？",function(){
				leadingOutTeachers();	
			});
		});
	}
	function initSmPages(){
		var rcH = $(".body-right",parent.document).height() - $(".right-title").height()-3;
		$(".right-content").height(rcH);
		
		var cdsH = $(".right-content").height() - $(".content-title").height() - 40;
		$(".content-data-show").height(cdsH);
	}
})();